package com.sky.myapplication.kotlin.kotlinActivity

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.sky.myapplication.R
import com.sky.myapplication.java.activity.ThreeActivity
import java.util.*

/**
 * Created by Min
 * Time 2021/6/19
 * Desc Kotlin编写同样的类
 */

//kotlin中没有extends，implements，继承直接类名（），实现接口直接接口名 https://blog.csdn.net/qq_33210042/article/details/90044334
class AnotherKotlinActivity: AppCompatActivity(), View.OnClickListener{
    //lateinit属性 https://zhuanlan.zhihu.com/p/31297995/
    lateinit var tv_log: TextView
    lateinit var btn_jump: Button

    var log: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_another)

        tv_log = findViewById(R.id.tv_log)
        btn_jump = findViewById(R.id.btn_jump)

        btn_jump.setOnClickListener(this)

        log += "onCreate"
        tv_log.setText(log)
        Log.d("", "onCreate")


//            Intent intent = new Intent(this, WebViewActivity.class);
//            startActivity(intent);

//            ClipboardManager clip = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
//            if (clip != null) {
//                clip.setPrimaryClip(ClipData.newPlainText(null, "123")); // 复制
//            }
        val aa = "1111,2222,333"
        var bb = Arrays.asList(*aa.split(",").toTypedArray()).toTypedArray() as ArrayList<String?>
        Log.i("aa", ""+bb)
    }

    override fun onClick(v: View?) {
        //kotlin when 替代了 java switch
        when (v?.id) {
            R.id.btn_jump -> {
                //两种写法都行：ThreeActivity().javaClass  ThreeActivity::class.java
//                var intent = Intent(this, ThreeActivity().javaClass)
                intent.setClass(this, ThreeActivity::class.java)
                startActivity(intent)
            }
        }
    }

    override fun onStop() {
        super.onStop()

        log += "onStop"
        tv_log.setText(log)
        Log.d("", "onStop")
    }

    override fun onRestart() {
        super.onRestart()

        log += "onRestart"
        tv_log.setText(log)
        Log.d("", "onRestart")
    }

    override fun onResume() {
        super.onResume()

        log += "onResume"
        tv_log.setText(log)
        Log.d("", "onResume")
    }

    override fun onPause() {
        super.onPause()

        log += "onPause"
        tv_log.setText(log)
        Log.d("", "onPause")
    }

    override fun onDestroy() {
        super.onDestroy()

        log += "onDestroy"
        tv_log.setText(log)
        Log.d("", "onDestroy")
    }
}